package com.dobbinsoft.iotechn.device.api.open;

import com.alibaba.fastjson.JSONObject;
import com.dobbinsoft.iotechn.core.annotation.HttpMethod;
import com.dobbinsoft.iotechn.core.annotation.HttpOpenApi;
import com.dobbinsoft.iotechn.core.annotation.HttpParam;
import com.dobbinsoft.iotechn.core.annotation.HttpParamType;
import com.dobbinsoft.iotechn.core.annotation.param.NotNull;
import com.dobbinsoft.iotechn.core.annotation.param.Range;
import com.dobbinsoft.iotechn.core.exception.ServiceException;
import com.dobbinsoft.iotechn.core.model.Page;
import com.dobbinsoft.iotechn.device.dto.UserDeviceDTO;
import com.dobbinsoft.iotechn.device.dto.DeviceUserDTO;

import java.util.List;

/**
 * Description: 为用户提供的设备服务
 * User: rize
 * Date: 2020/6/22
 * Time: 17:18
 */
@HttpOpenApi(group = "device", description = "为用户提供的设备服务")
public interface DeviceService {

    /**
     * 第一次绑定的用户作为 这个设备的管理员，若以后有其他用户也需要使用此设备，将由设备管理员审核
     * @return
     * @throws ServiceException
     */
    @HttpMethod(description = "将用户和设备进行绑定")
    public String bindDevice(
            @NotNull @HttpParam(name = "accessKeyId", type = HttpParamType.COMMON, description = "设备的唯一标识") String accessKeyId,
            @NotNull @HttpParam(name = "userId", type = HttpParamType.USER_ID, description = "用户ID") Long userId) throws ServiceException;

    @HttpMethod(description = "列举用户已绑定的设备")
    public Page<UserDeviceDTO> listDevices(
            @HttpParam(name = "pageNo", type = HttpParamType.COMMON, description = "页码") Integer pageNo,
            @Range(max = 30) @HttpParam(name = "pageSize", type = HttpParamType.COMMON, description = "页码长度", valueDef = "20") Integer pageSize,
            @NotNull @HttpParam(name = "userId", type = HttpParamType.USER_ID, description = "用户ID") Long userId) throws ServiceException;

    @HttpMethod(description = "向设备发送命令")
    public String sendCmd(
            @NotNull @HttpParam(name = "deviceId", type = HttpParamType.COMMON, description = "设备Id") Long deviceId,
            @NotNull @HttpParam(name = "cmd", type = HttpParamType.COMMON, description = "命令") String cmd,
            @HttpParam(name = "param", type = HttpParamType.COMMON, description = "额外参数") JSONObject param,
            @NotNull @HttpParam(name = "userId", type = HttpParamType.USER_ID, description = "用户ID") Long userId) throws ServiceException;

    // 设备管理相关
    @HttpMethod(description = "列举设备用户")
    public List<DeviceUserDTO> listDeviceUser(
            @NotNull @HttpParam(name = "deviceId", type = HttpParamType.COMMON, description = "设备Id") Long deviceId,
            @NotNull @HttpParam(name = "userId", type = HttpParamType.USER_ID, description = "用户ID") Long userId) throws ServiceException;

    @HttpMethod(description = "列举出待审核列表")
    public List<DeviceUserDTO> listDeviceUserWaitAudit(
            @NotNull @HttpParam(name = "userId", type = HttpParamType.USER_ID, description = "用户ID") Long userId) throws ServiceException;

    @HttpMethod(description = "审核使用申请")
    public String auditDeviceUser(
            @NotNull @HttpParam(name = "deviceUserId", type = HttpParamType.COMMON, description = "申请使用 '设备用户' ID(非UserDO.id)") Long deviceUserId,
            @Range(min = 2, max = 3) @NotNull @HttpParam(name = "status", type = HttpParamType.COMMON, description = "目标状态 2.允许使用 3.拒绝使用") Integer status,
            @NotNull @HttpParam(name = "userId", type = HttpParamType.USER_ID, description = "用户ID") Long userId) throws ServiceException;

}
